import java.io.*;
import java.util.ArrayList;

public class StuTest1 {
    public static void main(String[] args) throws IOException {
        FileWriter fw = new FileWriter("d:\\男生寝室管理信息.txt");
        ArrayList<Student> stus = getStudentList();
        for (int i = 0; i < stus.size(); i++) {
            Student stu = stus.get(i);
            if ("男".equals(stu.getSex())) {
                fw.write(stu.getXuehao() + "," + stu.getYuanxi() + "," + stu.getName()
                        + "," + stu.getLuodong() + "," + stu.getLuoceng() + "," + stu.getMenpai()
                        + "," + stu.getChuangwei());
                fw.write("\n");
            }
        }

        fw.close();

    }

    public static ArrayList<Student> getStudentList() throws IOException {
        File sushe = new File("d:\\sushe.txt");
        FileReader fr = new FileReader(sushe);
        BufferedReader br = new BufferedReader(fr);
        ArrayList<Student> stus = new ArrayList<>();
        String hang;
        while ((hang = br.readLine()) != null) {
            String[] hangs = hang.split(",");
            Student s = new Student();
            s.setXuehao(hangs[0]);
            s.setName(hangs[1]);
            s.setSex(hangs[2]);
            s.setYuanxi(hangs[5]);
            s.setLuodong(hangs[6]);
            s.setLuoceng(hangs[7]);
            s.setMenpai(Integer.valueOf(hangs[3]));
            s.setChuangwei(Integer.valueOf(hangs[4]));

            stus.add(s);

        }
        return stus;
    }
}